package tasks.leetcode;

public class TaskIntToRoman {
    public static void main(String[] args) {
        String s = new TaskIntToRoman().intToRoman(9004);
        System.out.println(s);
    }

    /**
     * 自定义的数组要丰富；13个元素;
     * 当前的num 的判断条件是大于或者等于；这个和二分法的是一致的；
     * @param num
     * @return
     */
    public String intToRoman(int num) {
        int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        // 要确保你写的symbol的字符是对的！
        String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < values.length; i++) {
            int currentValue = values[i];
            while (num >= currentValue) {
                num -= currentValue;
                stringBuilder.append(symbols[i]);
            }
            if (num == 0) {
                break;
            }

        }
        return stringBuilder.toString();
    }

}
